<template>
  <el-dialog :visible.sync="dialogVisible" width="390px" :before-close="handleClose">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="70px">
      <div class="title">修改密码</div>
      <el-form-item label="手机号码" prop="tel">
        <el-input
          v-model="ruleForm.mobile"
          placeholder="请输入手机号码"
        ></el-input>
      </el-form-item>
      <el-form-item label="验证码" prop="code">
        <el-input v-model="ruleForm.code" placeholder="请输入验证码"></el-input>
        <sendCode :mobile="ruleForm.mobile" event="changepwd"></sendCode>
      </el-form-item>
      <el-form-item label="新密码" prop="password">
        <el-input
          v-model="ruleForm.password"
          placeholder="请输入密码"
          show-password
        ></el-input>
      </el-form-item>
      <el-form-item label="确认密码" prop="password">
        <el-input
          v-model="ruleForm.repassword"
          placeholder="请再次输入密码"
          show-password
        ></el-input>
      </el-form-item>
      <div class="btn pointer" @click="onSubmit">确认修改</div>
    </el-form>
  </el-dialog>
</template>

<script>
export default {
  name: "loginView",
  data() {
    return {
      dialogVisible: false,
      ruleForm: {
        mobile: "",
        password: "",
		repassword:"",
        code: "",
      },
      rules: {
        // tel: [{ message: "请输入手机号码", trigger: "blur" }],
        // password: [{ message: "请输入密码", trigger: "blur" }],
      },
    };
  },
  props: {
    visible: {
      default: false,
    },
  },
  components: {
    sendCode: () => import("@/components/popup/sendCode.vue"),
  },
  watch: {
    visible(newVal) {
      this.dialogVisible = newVal;
    },
  },
  methods: {
	  handleClose() {
	    this.dialogVisible = false;
	    this.$emit("update:visible", false);
	  },
    onSubmit() {
		if(this.ruleForm.password !== this.ruleForm.repassword){
			this.$message.error("两次密码输入不一致");
			return false;
		}
      this.$post("/api/user/changepwd", this.ruleForm).then((res) => {
        if (res.code == 1) {
          this.$message.success(res.msg);
		  this.handleClose();
        } else {
          // this.$message.error(res.msg);
        }
      });
    },
  },
};
</script>

<style scoped lang="scss">
::v-deep .el-dialog__body {
  padding: 0;
}
::v-deep .el-dialog__header {
  padding: 0;
}
::v-deep .el-form {
  padding: 30px 35px;
  .title {
    text-align: center;
    font-size: 24px;
    padding-bottom: 20px;
  }
  .el-cascader {
    width: 100%;
  }
  .btn {
    text-align: center;
    color: #fff;
    background: #b08c45;
    border-radius: 4px;
    line-height: 40px;
    margin-bottom: 20px;
  }
  .bottom {
    display: flex;
    justify-content: space-between;
  }
}
@media screen and (max-width: 768px) {
  :deep .el-dialog {
    width: 90% !important;
  }
}
</style>
